package com.xinqi.modules.prepare.common.enums;

import com.xinqi.modules.prepare.common.constant.PrepareConstant;

import java.util.function.Supplier;

import static com.xinqi.common.base.error.CommonErrors.BAD_REQUEST;

/**
 * 备课区限制处理枚举
 *
 * @author linkai
 * @date 2023/3/24
 */
public enum PrepareLimitEnum {
    文件夹深度(PrepareConstant.FOLDER_DEPTH, "文件夹深度已超过最大限制"),
    用户加入备课区数量上限(5, "用户加入的备课区数量已达上限"),
    协同备课成员数量上限(50, "协同备课成员数量已达上限"),
    备课区创建上限(5, "备课区创建已超过上限"),
    文件列表大小限制(PrepareConstant.FILES_SIZE_LIMITED, "文件列表大小已超过最大限制"),
    文件列表数量限制(PrepareConstant.FILES_NUM_LIMITED, "文件列表数量已超过最大限制"),
    备课区容量限制(PrepareConstant.PREPARE_CAPACITY, "文件夹深度已超过最大限制"),
    备课区题目限制(PrepareConstant.QUESTION_BANK_LIMITED, "该备课区题目已达上限"),
    试题夹题目限制(PrepareConstant.QUESTION_FOLDER_LIMITED, "该试题夹题目已达上限"),
    互动视频帧题目限制(PrepareConstant.VIDEO_POINT_LIMITED, "每个互动环节只能添加10个试题"),
    互动视频帧限制(PrepareConstant.VIDEO_POINT_LIMITED, "该互动课件帧已达上限"),
    互动课件切片题目限制(PrepareConstant.COURSEWARE_PART_LIMITED, "该页题目已达上限"),
    ;

    private final long limitNum;
    private final String error;

    PrepareLimitEnum(long limitNum, String error) {
        this.limitNum = limitNum;
        this.error = error;
    }

    public void check(long num) {
        BAD_REQUEST.check(validate(num), error);
    }

    public void check(Supplier<Integer> s) {
        BAD_REQUEST.check(validate(s.get()), error);
    }

    public void check(int num, String error) {
        BAD_REQUEST.check(validate(num), error);
    }

    public boolean validate(long num) {
        return num <= limitNum;
    }
}
